#include "../base/logger.h"
#include "vec2.h"
#include "vec3.h"
#include "vec4.h"
#include "box2.h"
#include "box3.h"
#include "mat4.h"

USE_JLIB_NS

extern f32 rscalar ();
extern Vec2 rvec2 ();
extern Vec3 rvec3 ();
extern Vec4 rvec4 ();
extern Box2 rbox2 ();
extern Box3 rbox3 ();
extern Mat4 rmat4 ();

extern void pboolean (const char* i, bool v);
extern void pscalar (const char* i, f32 v);
extern void pvec2 (const char* i, Vec2 v);
extern void pvec3 (const char* i, Vec3 v);
extern void pvec4 (const char* i, Vec4 v);
extern void pbox2 (const char* i, Box2 v);
extern void pbox3 (const char* i, const Box3& v);
extern void pmat4 (const char* i, const Mat4& m);

static void test_vec2 ();
static void test_vec3 ();
static void test_vec4 ();
static void test_box2 ();
static void test_box3 ();
static void test_mat4 ();


int main (int argc, char** argv) {
  test_vec2();
  test_vec3();
  test_vec4();
  test_box2();
  test_box3();
  test_mat4();
  return 0;
}

static void test_vec2 () {
  log_w("========== Vec2 Test ==========");
  Vec2 v1 = rvec2();
  pvec2("v1", v1);
  Vec2 v2 = rvec2();
  pvec2("v2", v2);
  pscalar("v1 & v2", v1 & v2);
  pscalar("v1 ^ v2", v1 ^ v2);
}

static void test_vec3 () {
  log_w("========== Vec3 Test ==========");
  Vec3 v1 = rvec3();
  pvec3("v1", v1);
  Vec3 v2 = rvec3();
  pvec3("v2", v2);
  pscalar("v1 & v2", v1 & v2);
  pvec3("v1 ^ v2", v1 ^ v2);
  pvec3("slerp(v1, v2, 0.37)", Vec3::slerp(v1, v2, 0.37));
}

static void test_vec4 () {
  log_w("========== Vec4 Test ==========");
  Vec4 v1 = rvec4();
  pvec4("v1", v1);
  Vec4 v2 = rvec4();
  pvec4("v2", v2);
  pvec4("blend(v1, v2)", Vec4::blend(v1, v2));
}

static void test_box2 () {
  log_w("========== Box2 Test ==========");
  Box2 b1 = rbox2();
  pbox2("b1", b1);
  Box2 b2 = rbox2();
  pbox2("b2", b2);
  Vec2 v1 = rvec2();
  pvec2("v1", v1);
  pbox2("b1 & b2", b1 & b2);
  pbox2("b1 | b2", b1 | b2);
  pboolean("b1 contains v1", b1.contains(v1));
  pboolean("b1 contains b2", b1.contains(b2));
  pboolean("b1 intersect b2", b1.intersect(b2));
}

static void test_box3 () {
  log_w("========== Box3 Test ==========");
  Box3 b1 = rbox3();
  pbox3("b1", b1);
  Box3 b2 = rbox3();
  pbox3("b2", b2);
  Vec3 v1 = rvec3();
  pvec3("v1", v1);
  pbox3("b1 & b2", b1 & b2);
  pbox3("b1 | b2", b1 | b2);
  pboolean("b1 contains v1", b1.contains(v1));
  pboolean("b1 contains b2", b1.contains(b2));
  pboolean("b1 intersect b2", b1.intersect(b2));
}

static void test_mat4 () {
  log_w("========== Mat4 Test ==========");
  Mat4 m1 = rmat4();
  pmat4("m1", m1);
  Vec4 v1 = rvec4();
  pvec4("v1", v1);
  pvec4("m1 * v1", m1 * v1);
}